<!DOCTYPE html>
<html>
<head>
<!--[if lt IE 7]>
<div class="ie6_error">还在用<strong>漏洞百出的IE6浏览器</strong>么？为了您的网络安全，请升级浏览器 <a target="_blank"
href="http://browsehappy.com">立即升级</a>
</div>
<![endif]-->

<meta charset="utf-8">
<title>审批中心-文具1号</title>
<meta name="description"
content="文具1号作为上海办公用品供货商公司,专为世界500强企业及SOHO办公族提供网上商城一站式办公耗材批发及采购服务,一站式选购办公日用文具用品,厂家直销,好货又便宜【阳光采购就上文具1号 阳光价格 老板放心 品质保障 员工省力】"/>
<meta name="keywords" content="办公用品,办公文具,办公文具网站,文具网站,办公用品网,文具采购网,金万年"/>
<meta name="copyright" content="上海易推信息科技有限公司"/>
<meta name="renderer" content="webkit">
<base href="<?php echo base_url(); ?>"/>
<link rel="shortcut icon" href="favicon.ico"/>
<link rel="stylesheet" href="public/js/layui/css/layui.css">
<link rel="stylesheet" type="text/css" href="public/css/base.css"/>
<link rel="stylesheet" type="text/css" href="public/css/common.css"/>
<link rel="stylesheet" type="text/css" href="public/css/cost-center.css"/>
<link href="public/css/yuan.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="public/css/list_bought.css"/>
<link rel="stylesheet" type="text/css" href="public/css/order-manage.css"/>
<!--[if lte IE 9]>
<script type="text/javascript" src="public/js/html5shiv-printshiv-3.js"></script>
<![endif]-->
</head>
<body>
    <div class="bg">
        <!--common - head -->
        <?php $this->load->view('common/header.php'); ?>
        <!--common - head end-->
        <?php
//                $shop_user_id=2;
        if (isset($this->session->customer_id)) {
            $sql = 'select identity,id from app_customer WHERE id = ' . $this->session->customer_id;
            $identitys = $this->db->query($sql)->row_array();
            if ($identitys['identity'] == 1) {
                $sql = "select is_account,account_period_type from app_admin WHERE customer_id = " . $this->session->customer_id;
                $admin_info = $this->db->query($sql)->row_array();
                if ($admin_info['is_account'] == 1) {
                    if ($admin_info['account_period_type'] == 2) {
                        $bills = $this->db->where('customer_id', $identitys['id'])->where('status', 0)->from('app_bill ')->get()->result_array();
                        $bill = count($bills);
                    } else {
                        $bills = $this->db->where('customer_id', $identitys['id'])->where(array('status' => 0, 'bill_date != ' => NULL))->from('app_bill ')->join('app_bill_month', 'app_bill_month.bill_id = app_bill.id')->get()->result_array();
                        $bill = count($bills);
                    }
                }
            }
            $customer_id = $identitys['id'];
            $news = $this->db->where('receiver_customer_id', $identitys['id'])->where('read_status', 0)->from('message_history')->get()->result_array();
//获取admin下面的子辈和孙辈的(包含自己)
            $member = $this->db->from('app_customer')->select("id")->where('parent_id', $customer_id)->get()->result_array();
            $str[] = $customer_id;
            foreach ($member as $k => $v) {
                $str[] = $v['id'];
            }
            foreach ($member as $k => $v) {
                $where = array('parent_id' => $v['id']);
                $row = $this->db->from('app_customer')->select("id")->where($where)->get()->result_array();
                foreach ($row as $key => $val) {
                    $str[] = $val['id'];
                }
            }
            foreach ($str as $key => $value) {
                if($value == $customer_id){
                    unset($str[$key]);
                }
            }
            if(count($str) == ""){
                $str[] = "-1";
            }
            $count1 = $this->db->where_in('customer_id', $str)->where('status', 2)->from('app_temp')->count_all_results();
            $count2 = $this->db->where_in('customer_id', $str)->where('status', 4)->from('app_temp')->count_all_results();
            $count = $count1 + $count2;
            $newspull = count($news);
        }
        ?>
        <div class="container mt30">
            <div class="my-center-container">
                <div class="my-center-sidebar">
                    <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="demo">
                        <li class="layui-nav-item layui-nav-itemed "><a
                            href="<?php echo base_url('approve/index?id=2'); ?>">审批中心（<?php echo $count; ?>）</a>
                        </li>
                        <?php if (isset($admin_info)): ?>
                            <?php if ($identitys['identity'] == 1 && $admin_info['is_account'] == 1): ?>
                                <li class="layui-nav-item "><a
                                    href="<?php echo base_url('news/news_bill'); ?>">账期提醒（<?php echo $bill; ?>）</a>
                                </li>
                            <?php endif; ?>
                        <?php endif; ?>
                        <li class="layui-nav-item"><a style="border-bottom:0;"
                            href="<?php echo base_url('news/news_pull'); ?>">消息通知<em>（<?php echo $newspull; ?>
                        ）</em></a></li>
                    </ul>
                </div>

                <div class="my-center-right" style="overflow:visible; border: none;background-color: #f9f9f9">


                    <div class="my-center-right-cont" style="padding: 0;">
                        <div class="order-manage-cont" style="margin-top:0; width:992px; padding: 0">
                            <div id="main-content">

                                <div class="bought-list">
                                    <p class="bought-list-tit">
                                        审批中心
                                    </p>
                                    <form class="skin-gray clearfix bought-search" action="" method="post"
                                    style="padding-bottom:0;">
                                    <!--bought-search-more -->
                                    <input type="hidden" name="ordertype" value="0">
                                    <input type="hidden" id="visibility" name="visibility" value="0">
                                    <input type="hidden" id="page" name="page" value="1">
                                    <input type="hidden" name="auctionStatus" value="ALL">
                                    <div class="remide-box" gdata-spm="7" style="padding:5px 0">
                                        <ul>
                                            <li><a href="<?php echo base_url() ?>approve/index?id=2"
                                                class="checkbox-icon <?php if ($id == 2): ?>select<?php endif; ?>">待审批</a>
                                            </li>
                                            <li><a href="<?php echo base_url() ?>approve/index?id=1"
                                                class="checkbox-icon <?php if ($id == 1): ?>select<?php endif; ?>">审批通过</a>
                                            </li>
                                            <li><a href="<?php echo base_url() ?>approve/index?id=3"
                                                class="checkbox-icon <?php if ($id == 3): ?>select<?php endif; ?>">审批驳回</a>
                                            </li>
                                            <li><a href="<?php echo base_url() ?>approve/index?id=0"
                                                class="checkbox-icon <?php if ($id == "0"): ?>select<?php endif; ?>">订单取消</a>
                                            </li>
                                            <li><a href="<?php echo base_url() ?>approve/index"
                                                class="checkbox-icon <?php if ($id == ''): ?>select<?php endif; ?>">全部状态</a>
                                            </li>
                                        </ul>

                                    </div>
                                </form>
                                <div class="corporate-invoice-table-box w100 bg-fff">
                                    <table border="1" class="corporate-invoice-tab corporate-invoice-sp">
                                        <thead>
                                            <tr>
                                                <th width="60">序号</th>
                                                <th width="100">成本中心</th>
                                                <th width="110">账号</th>
                                                <th width="110">联系方式</th>
                                                <th>数量</th>
                                                <th>订单金额(元)</th>
                                                <th width="120">提交时间</th>
                                                <th width="110">原由</th>
                                                <th width="240" colspan="2">审批状态</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($list as $k => $v): ?>
                                                <?php if ($v['status'] == 1): ?>
                                                    <tr>
                                                        <td class="checkbox-icon tit" colspan="10">
                                                            <span class=" icon"></span> 订单编号：<?= $v['shop_order_bn'] ?>
                                                        </td>
                                                    </tr>
                                                <?php endif; ?>
                                                <tr>
                                                    <td>
                                                        <a href="<?php echo base_url() ?>approve/detail/?id=<?= $v['id'] ?>" style="color: #007aff;text-decoration: underline;">SP<?= $v['id']?></a>
                                                    </td>
                                                    <td class="td01"><?= $v['cost_center_name'] ?></td>
                                                    <td class="color-blue">
                                                        <a href="<?php echo base_url()?>cost_center/manager_user_edit/?id=<?php echo $v['customer_id']?>" style="color: #007aff;text-decoration: underline;"> <?= $v['customer_name'] ?></a>
                                                    </td>
                                                    <td><?= $v['customer_tel'] ?> </td>
                                                    <td><?= count(json_decode($v['detail'], true)['products']) ?> </td>
                                                    <td><?= $v['money'] ?></td>
                                                    <td><?= mb_substr(str_replace('-', '/', $v['created_at']), 0, strlen(str_replace('-', '/', $v['update_at'])) - 3) ?></td>
                                                    <td class="corporate-invoice-tab-time td02">
                                                        <?= $v['reason'] ?>
                                                    </td>
                                                    <?php if ($v['status'] == 2 || $v['status'] == 4): ?>
                                                        <td class="corporate-invoice-tab-time tal">
                                                            审批已耗时：<?= $v['wait_time'] ?><br>
                                                        </td>
                                                        <?php elseif ($v['status'] == 1 || $v['status'] == 0): ?>
                                                            <td class="corporate-invoice-tab-time tar">
                                                                <?= mb_substr($v['update_at'], 0, strlen($v['update_at']) - 3) ?>
                                                            </td>
                                                            <?php else: ?>
                                                                <td class="corporate-invoice-tab-time tal">
                                                                    <?= mb_substr($v['update_at'], 0, strlen($v['update_at']) - 3) ?>
                                                                    <br>
                                                                    原因：<?= $v['approve_reason'] ?>
                                                                </td>
                                                            <?php endif; ?>


                                                            <?php if ($v['status'] == 1): ?>
                                                                <td class="corporate-invoice-tab-time tar">
                                                                    <span class=" corporate-invoice-tab-pass bg-pic_pass"></span>
                                                                </td>
                                                                <?php elseif ($v['status'] == 2): ?>
                                                                    <?php if ($identity == 2): ?>
                                                                        <td>
                                                                            <div class="corporate-invoice-tab-btn">
                                                                                <a href="javascript:;" class="submit approve"
                                                                                val="<?= $v['id'] ?>">通过</a>
                                                                                <a href="javascript:;" class="cancel"
                                                                                val="<?= $v['id'] ?>">驳回</a>
                                                                            </div>
                                                                        </td>
                                                                        <?php else: ?>
                                                                            <td>
                                                                                <div class="corporate-invoice-tab-btn" style="">
                                                                                    <a style="text-decoration: none;border: 0;width: auto;">Manager审核中</a>
                                                                                </div>
                                                                            </td>
                                                                        <?php endif; ?>

                                                                        <?php elseif ($v['status'] == 4): ?>
                                                                            <?php if ($identity == 1): ?>
                                                                                <td>
                                                                                    <div class="corporate-invoice-tab-btn">
                                                                                        <a href="javascript:;" class="submit approve"
                                                                                        val="<?= $v['id'] ?>">通过</a>
                                                                                        <a href="javascript:;" class="cancel"
                                                                                        val="<?= $v['id'] ?>">驳回</a>
                                                                                    </div>
                                                                                </td>
                                                                                <?php elseif($identity == 3): ?>
                                                                                    <td>
                                                                                        <div class="corporate-invoice-tab-btn">
                                                                                            <a style="text-decoration: none;border: 0;">审批通过</a>
                                                                                            <a style="text-decoration: none;border: 0;">Admin审核中</a>
                                                                                        </div>
                                                                                    </td>
                                                                                    <?php elseif($identity == 2): ?>
                                                                                        <td>
                                                                                            <div class="corporate-invoice-tab-btn">
                                                                                                <a style="text-decoration: none;border: 0;">Admin审核中</a>
                                                                                            </div>
                                                                                        </td>
                                                                                    <?php endif; ?>
                                                                                    <?php elseif ($v['status'] == 5 || $v['status'] == 3): ?>
                                                                                        <td class="corporate-invoice-tab-time tac">
                                                                                            <span class="color-red">审批驳回</span>
                                                                                        </td>
                                                                                        <?php elseif ($v['status'] == 0): ?>
                                                                                            <td class="corporate-invoice-tab-time tac">
                                                                                                <span class="color-red">订单已取消</span>
                                                                                            </td>
                                                                                        <?php endif; ?>
                                                                                    </tr>
                                                                                <?php endforeach; ?>

                                                                            </tbody>
                                                                        </table>

                                                                        <div class="corporate-invoice-page-box">
                                                                            <?php if ($total_page > 1): ?>
                                                                                <?php if ($nowPage > 1): ?>
                                                                                    <a href="<?= $preurl ?>" class="page-prev">上一页</a>
                                                                                <?php endif; ?>
                                                                                <?php if ($nowPage != $total_page): ?>
                                                                                    <a href="<?= $nexturl ?>" class="page-next">下一页</a>
                                                                                <?php endif; ?>
                                                                            <?php endif; ?>
                                                                        </div>


                                                                    </div>


                                                                </div>
                                                                <!--end bought-list-->
                                                            </div>

                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <?php $this->load->view('common/bottom.php'); ?>

                                    <div class="mask none"></div>

                                    <div class="pop pop-account-activation bg-padding-inside none tongyi" style="height: 283px">
                                        <a href="javascript:;" class="close bg-btn_close_n"></a>
                                        <p class="top-tit">
                                            <span class="bg-logo_popup"></span>
                                        </p>
                                        <div class="cont">
                                            <p class="tit" style="margin-top:20px; margin-bottom:50px;">同意该订单通过！</p>
                                            <div class="btn-box">
                                                <button class="adjustment-budget-submit adjustment-budget-submit-tongyi">确 定</button>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="pop pop-account-activation bg-padding-inside none tongguo" style="height: 283px">
                                        <a href="javascript:;" class="close bg-btn_close_n"></a>
                                        <p class="top-tit">
                                            <span class="bg-logo_popup"></span>
                                        </p>
                                        <div class="cont">
                                            <p class="tit">审批通过</p>
                                            <p class="intro" style="width:244px; margin: 0 auto">
                                                由于该订单已超出您当前的预算
                                                审批通过后将交由admin进行审批
                                            </p>
                                            <div class="btn-box">
                                                <button class="adjustment-budget-submit adjustment-budget-submit-tongguo">确 定</button>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="pop pop-account-activation bg-padding-inside none bohui" style="height: 506px">
                                        <a href="javascript:;" class="close bg-btn_close_n"></a>
                                        <p class="top-tit">
                                            <span class="bg-logo_popup"></span>
                                        </p>
                                        <div class="cont" style="height: auto">
                                            <p class="tit">审批驳回</p>
                                            <p class="intro" style="width:314px; margin: 0 auto">
                                                <a href="javascript:;" class="pop-approve-center-radio specify-reason">
                                                    <span class="icon select" value="无增加预算计划">选择框</span>
                                                    理由一无增加预算计划
                                                </a>
                                                <a href="javascript:;" class="pop-approve-center-radio specify-reason">
                                                    <span class="icon " value="无增加单品预算计划">选择框</span>
                                                    理由二无增加单品预算计划
                                                </a>
                                                <a href="javascript:;" class="pop-approve-center-radio specify-reason">
                                                    <span class="icon" value="无增加商品类别计划">选择框</span>
                                                    理由三无增加商品类别计划
                                                </a>
                                                <a href="javascript:;" class="pop-approve-center-radio other-reason">
                                                    <span class="icon">选择框</span>
                                                    其他理由
                                                </a>
                                            </p>
                                            <textarea name="other" class="pop-approve-center-textarea" cols="30" rows="10" placeholder="请输入审批驳回理由（0~200个字符"
                                            style="display: none;" "></textarea>
                                            <div class="btn-box" style="display: block;float: left;">
                                                <button class="adjustment-budget-submit bohui_insure">确 定</button>
                                            </div>
                                        </div>
                                    </div>

                                    <script type="text/javascript" src="public/js/jquery.min.js"></script>
                                    <script src="public/js/layui/layui.js"></script>
                                    <script type="text/javascript" src="public/js/index.js"></script>
                                    <script type="text/javascript" src="public/js/owl.carousel.min.js"></script>

                                    <script>
                                        layui.use(['element', 'form', 'layedit', 'laydate', 'upload'], function () {
var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
var form = layui.form
, layer = layui.layer
, layedit = layui.layedit
, laydate = layui.laydate;
var $ = layui.jquery
, upload = layui.upload;

//监听导航点击
element.on('nav(demo)', function (elem) {
//console.log(elem)
//      layer.msg(elem.text());
});
//日期
laydate.render({
    elem: '#date-star'
});
laydate.render({
    elem: '#date-end'
});
laydate.render({
    elem: '#date'
});
//监听提交
form.on('submit(demo1)', function (data) {
    layer.alert(JSON.stringify(data.field), {
        title: '最终的提交信息'
    });
    return false;
});


});
</script>
<script>
    $(function () {
        $(".checkbox-icon").click(function () {
            $(this).toggleClass('select');
            $(this).parent().siblings().find('.checkbox-icon').removeClass('select')
        });

        $(".pop-approve-center-radio").click(function () {
            $(this).find('.icon').addClass('select');
            $(this).siblings().find('.icon').removeClass('select');
        });

        $('#searchBtn').click(function () {
            var nexturl = "<?=$nexturl?>";
            location.href = nexturl
        })

        $('.cancel').click(function () {
            $('.mask').css('display', 'block');
            $('.bohui').css('display', 'block');
            $('.bohui').removeClass('none');
            var id = $(this).attr('val');
            $('.bohui_insure').attr('val', id);
        })

        $('.other-reason').click(function () {
            $('textarea').css('display', 'block')
        })
        $('.specify-reason').click(function () {
            $('textarea').css('display', 'none')
        })

//驳回提交
$('.bohui_insure').click(function () {
    var id = $(this).attr('val');
    var content = $('.intro .select').attr('value');
    if (content == undefined) {
        var content = $("textarea[name=other]").val();
    }
    if (content == "") {
        layer.msg('驳回理由不可为空');
        return false;
    }
    $.ajax({
        type: "POST",
        url: "<?php echo base_url()?>approve/cancel",
        data: {
            id: id,
            content: content
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                layer.msg(data.msg);
                setTimeout(function () {
                    window.location.reload();
                }, 1000)
            } else {
                layer.msg(data.msg);
            }
        }

    });
})

$('.approve').click(function () {
    var id = $(this).attr('val');
    $.ajax({
        type: "POST",
        url: "approve/judge",
        data: {
            id: id
        },
        dataType: "json",
        success: function (data) {
            if (data.code == 0) {
                $('.adjustment-budget-submit-tongyi').attr('status',data.data);
                $('.adjustment-budget-submit-tongyi').attr('val',id);
                $('.tongyi').removeClass('none'); 
                $('.tongyi').show(); 
                $('.mask').removeClass('none');     
                $('.mask').show();           
            } else if (data.code == 1) {
                $('.adjustment-budget-submit-tongguo').attr('status',data.data);
                $('.adjustment-budget-submit-tongguo').attr('val',id);
                $('.tongguo').removeClass('none'); 
                $('.tongguo').show(); 
                $('.mask').removeClass('none');     
                $('.mask').show(); 
            } else {
                layer.msg(data.msg);
            }
        }

    });
})


var flag = true;
//通过提交
$('.adjustment-budget-submit-tongyi,.adjustment-budget-submit-tongguo').click(function () {
    var id = $(this).attr('val');
    var status = $(this).attr('status');
    if(flag == false){
        return false;
    }
    flag = false;
    $.ajax({
        type: "POST",
        url: "approve/agree",
        data: {
            id: id,
            status: status
        },
        dataType: "json",
        success: function (data) {
            if (data.code == -1) {
                layer.msg(data.msg);
            } else {
                location.reload()    
            }
        }

    });
})
});
</script>
</body>
</html>